#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include "Chapter6_2.h"
using namespace std;
int main()
{
	//practice_6_30();
	//practice_6_33();
	//practice_6_37();
	//practice_6_42();
	//practice_6_44();
	//practice_6_51();
	//example_p221();
	practice_6_56();
	return 0;
}
bool str_subrange(const string &str1,const string &str2)
{
	if(str1.size()==str2.size())
		return str1==str2;
	auto size=(str1.size()<str2.size())?str1.size():str2.size();
	for(decltype(size) i=0;i!=size;++i){
		if(str1[i]!=str2[i])
			return false;
	}
	//return true;
}
void practice_6_30()
{
	string str1("sslld");
	string str2("sslldjil");
	cout<<str_subrange(str1,str2);
}
void print_v(vector<int> ::const_iterator beg,vector<int>::const_iterator end)
{
	if(beg!=end)
	{
		cout<<*beg++<<" ";
		print_v(beg,end);
	}
	else
		return ;
}
void practice_6_33()
{
	vector<int> v{1,2,3,4,5};
	print_v(v.cbegin(),v.cend());
}
//practice_6_36
string (*&func(void))[10]
{
	string (*result)[10];
	result= &test;
	cout<<&result<<endl;
	decltype(result) &r=result;
	return r;
}
arrT &func1(void)
{
	arrT result;
	result= &test;
	decltype(result) &r=result;
	return r;
}
auto func2()->string (*&)[10]
{
	string (*result)[10];
	result= &test;
	decltype(result) &r=result;
	return r;
}
decltype(test) *&func3(void)
{
	string (*result)[10];
	result= &test;
	decltype(result) &r=result;
	return r;
}
string *func4()
{
	return test;
}
decltype(odd) &arrPtr(int i)
{
	return (i%2)?odd:even;
}
void practice_6_36()
{
	cout<<(*func3())[5]<<endl;
}
void practice_6_37()
{
	cout<<arrPtr(3)[2];
}
string make_plural(size_t ctr,const string& word,const string& ending)
{
	return (ctr>1)?word+ending:word;
}
void practice_6_42()
{
	cout<<make_plural(7,"success")<<endl;
	cout<<make_plural(7,"failure")<<endl;
}
void practice_6_44()
{
	cout<<isShorter("zyl11ok","zyl22222f")<<endl;
}
void f()
{
	cout<<"f()"<<endl;
}
void f(int)
{
	cout<<"f(int)"<<endl;
}
void f(int,int)
{
	cout<<"f(int,int)"<<endl;
}
void f(double,double)
{
	cout<<"f(double,double=3.14)"<<endl;
}
void practice_6_51()
{
	//f(2.56,42);
	f(42);
	f(42,0);
	f(2.56,3.14);
}
bool lengthCompare(const string &s1,const string &s2)
{
	return (s1.size()<s2.size())?false:true; 
}
void example_p221()
{
	bool (*pf)(const string &,const string &);
	pf=&lengthCompare;
	bool b=pf("Hello","Shit");
	cout<<"result:"<<b<<endl;
}
int add(int a,int b)
{
	return a+b;
}
int subtract(int a,int b)
{
	return a-b;
}
int multiply(int a,int b)
{
	return a*b;
}
int divide(int a,int b)
{
	return a/b;
}
void practice_6_56()
{
	using IP=int(*)(int,int);
	IP f1=add;
	IP f2=subtract;
	IP f3=multiply;
	IP f4=divide;
	vector<IP> v{f1,f2,f3,f4};
	for(IP f:v)
		cout<<f(16,4)<<" ";
}